package cn.flying.cloud.system.position.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.system.position.entity.SysPostUser;
import cn.flying.cloud.system.position.service.SysPostUserService;

/**
 * 用户岗位信息表 前端控制器
 *
 * @author: admin
 * @date: 2023年04月19日 16:27
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/post/user")
public class SysPostUserController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysPostUserService sysPostUserService;

    /**
     * 分页查询用户岗位信息表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse<SysPostUser> page(@RequestBody PageRequest<SysPostUser> request) {
        return sysPostUserService.getPageList(request);
    }

    /**
     * 列表查询用户岗位信息表数据
     *
     * @param sysPostUser
     * @return
     */
    @PostMapping("list")
    public Rt<?> list(@RequestBody SysPostUser sysPostUser) {
        List<SysPostUser> list = sysPostUserService.getList(sysPostUser);
        return Rt.success(list);
    }

    /**
     * 查询用户岗位信息表详情数据
     *
     * @param sysPostUser
     * @return
     */
    @PostMapping("detail")
    public Rt<?> detail(SysPostUser sysPostUser) {
        return Rt.success(sysPostUserService.getOneObj(sysPostUser));
    }

    /**
     * 根据主键ID查询用户岗位信息表详情数据
     *
     * @param id
     * @return
     */
    @PostMapping("getById")
    public Rt<?> getById(Long id) {
        SysPostUser sysPostUser = sysPostUserService.getById(id);
        return Rt.success(sysPostUser);
    }

    /**
     * 保存用户岗位信息表数据
     *
     * @param sysPostUser
     * @return
     */
    @PostMapping("save")
    public Rt<?> save(@RequestBody SysPostUser sysPostUser) {
        if (Objects.isNull(sysPostUser.getId())) {
            // 新增
            sysPostUserService.createObj(sysPostUser);
        } else {
            // 更新
            sysPostUserService.updateObj(sysPostUser);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除用户岗位信息表数据
     *
     * @param sysPostUser
     * @return
     */
    @PostMapping("delete")
    public Rt<?> delete(SysPostUser sysPostUser) {
        sysPostUserService.deleteObj(sysPostUser);
        return Rt.success("删除成功！");
    }
}
